from flask_sqlalchemy import SQLAlchemy
from flask import Flask
import pymysql
app = Flask(__name__)



HOSTNAME = '127.0.0.1'
PORT = '3306'
DATABASE = 'flask_db'
USERNAME = 'root'
PASSWORD = 'Lc610256'

DB_URI = 'mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8'.format(USERNAME, PASSWORD, HOSTNAME, PORT, DATABASE)
app.config['SQLALCHEMY_DATABASE_URI'] = DB_URI
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config["SECRET_KEY"] = 'dfnsjfra'
# 将app的信息传递给数据库
db = SQLAlchemy(app)


# 学生表
class Student(db.Model):
    __tablename__= "student"
    id = db.Column(db.Integer,primary_key=True)
    name = db.Column(db.String(64),nullable=False)
    gender = db.Column(db.Enum("男","女"))
    phone = db.Column(db.String(11))


# 课程表
class Course(db.Model):
    __tablename__ = "course"
    id = db.Column(db.Integer,primary_key=True) # 主键
    name = db.Column(db.String(64),nullable=False)

# 教师表
class Teacher(db.Model):
    __tablename__ = "teacher"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64), nullable=False)
    gender = db.Column(db.Enum("男", "女"))
    phone = db.Column(db.String(11))
# 成绩表
# class Grade(db.Model):
#     __tablename__ = "grade"
#     id =
#     course_name =
#     grade =
#     student =


if __name__ == '__main__':
    # 先清空所有表，避免重复执行
    # db.drop_all()
    # 创建表
    db.create_all()